/*
 * @Author: 晟松
 * @Date: 2021-12-06 16:36:03
 * @LastEditors: 晟松
 * @LastEditTime: 2021-12-06 17:00:32
 * @FilePath: \mini-vue3d:\Code\node\koa2\volunteer-service\src\main\model\Test.js
 * @Description: test model 关联
 */
import Sequelize from "sequelize";
import { isPhone } from "@main/util/ValidateUtil";
import { ParamError } from "../common/CommonError";

export const modelName = "test";

const DataTypes = Sequelize.DataTypes;
// sequelize 会自动提供 id, created_at 和 updated_at 字段，所以这里就没配置了
export const attributes = {
  first: {
    type: Sequelize.STRING(20),
    // unique: true,
    validate: {
      // 里面的参数详解：https://www.cnblogs.com/dongfang159/p/7463604.html
      // 第二个参数是为了表示是异步的？这里有点不对，这里也不是异步啊
      /* isPhoneCheck(val, done) {
        // console.log("Sequelize检查val: ", val,typeof val);
        if (val) {
          if (!isPhone(val)) {
            throw new ParamError("电话号码格式不正确");
          }
        } else {
          console.log("else\n");
          throw new ParamError("电话号码不能为空");
        }
        done();
      }, */
    },
  },
  last: {
    type: Sequelize.STRING(64),
    validate: {
      /* check(val) {
        if (val) {
          if (val.length < 6) {
            throw new ParamError("密码不能小于6位");
          }
        } else {
          throw new ParamError("密码不能为空");
        }
      }, */
    },
  },
  nickName: Sequelize.STRING(50),
  sex: Sequelize.TINYINT,
};

export const options = {
  tableName: "t_user_reference",
};
